package cn.javaweb.group0.servlet;

import cn.javaweb.group0.entity.Module;
import cn.javaweb.group0.model.ModuleModel;
import cn.javaweb.library.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/module/delete")
public class ModuleDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.parseInt(req.getParameter("id"));

        ModuleModel moduleModel = new ModuleModel();
        Module module = moduleModel.getModule(id);
        if(module!=null){
            moduleModel.deleteModule(id);
            resp.getWriter().print(AjaxResult.success("删除成功"));
        }else{
            resp.getWriter().print(AjaxResult.error("模块不存在"));
        }

    }
}
